﻿using Furion;
using Furion.RemoteRequest.Extensions;
using iemtm.WeChat.Core.Managers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace iemtm.WeChat.Core.Util
{
    /// <summary>
    /// 与网页Api通讯
    /// </summary>
    public class WebApiCommunication
    {
        public static string ApiUrl= App.Configuration["AppProgramConfig:WebApiUri"];

        private readonly IWorkManager _workManager;
        public WebApiCommunication(IWorkManager workManager)
        {
            _workManager = workManager;
        }
        public static async Task<string> DeleteGen(string GeneratorId)
        {
            //var user = _workManager.CurrentUser;
            var workManager= App.GetService<IWorkManager>();
            var user = workManager.CurrentUser;
            var url= $"{ApiUrl}api/WeiXinServer/DeleteGen?GeneratorId={GeneratorId}&openId={user.WxOpenId}&prjCode={user.PrjCode}";
      
            var response = await url.GetAsync();
            string resultV = response.Content.ReadAsStringAsync().Result;
            return resultV;
        }

        /// <summary>
        /// 条件油机 更新页面缓存
        /// </summary>
        /// <param name="GensetNum"></param>
        /// <param name="DTUID"></param>
        /// <returns></returns>
        public static async Task<string> AddGenWXCacaht(string GensetNum,string DTUID)
        {
            //var user = _workManager.CurrentUser;
            var workManager = App.GetService<IWorkManager>();
            var LoginInfo = workManager.CurrentUser;
            var url = $"{ApiUrl}api/WeiXinServer/AddByWXCacaht?GensetNum={GensetNum}&DTUID={DTUID}&userCode={LoginInfo.UserCode}&openId={LoginInfo.WxOpenId}&prjCode={LoginInfo.PrjCode}";

           
            var response = await url.GetAsync();
            string resultV = response.Content.ReadAsStringAsync().Result;
            return resultV;
        }
    }
}
